package com.example.project.projectspringcloud.controller.front.workorder;

import com.example.project.projectspringcloud.common.Constants;
import com.example.project.projectspringcloud.controller.BaseController;
import com.example.project.projectspringcloud.entity.Page;
import com.example.project.projectspringcloud.entity.RespBody;
import com.example.project.projectspringcloud.entity.workorder.WorkOrder;
import com.example.project.projectspringcloud.service.workorder.WorkOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = "工单系统")
@Controller
@RequestMapping(value = "/workorder")
public class WorkOrderController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(WorkOrderController.class);

    @Autowired
    private WorkOrderService workOrderService;

    public String list(WorkOrder workOrder, Page page, Model model) {

        return "";
    }

    @ApiOperation(value = "API创建工单", notes = "创建工单")
    @PostMapping(value = "/add")
    @ResponseBody
    public RespBody add(WorkOrder workOrder) {
        try {
            workOrder.setStatus(1);
            workOrderService.save(workOrder);
            return RespBody.ok(true);
        } catch (Exception e) {
            logger.error("WorkOrderController - add - error", e);
            return RespBody.error(super.translateI18N(Constants.SystemMessage.SYSTEM_ERROR));
        }
    }
}
